package com.redstar.interesting.common.starter.multiDataSource;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * @author lihongxing
 */
public class DynamicDataSourceContext {
    private static final Logger log = LoggerFactory.getLogger(DynamicDataSourceContext.class);

    private static final ThreadLocal<String> DATA_SOURCE_HOLDER = new ThreadLocal<>();

    public static void setDataSource(String dataSource) {
        log.info("设置数据源为:{}", dataSource);
        DATA_SOURCE_HOLDER.set(dataSource);
    }

    public static String getDataSource(){
        String s = DATA_SOURCE_HOLDER.get();
        log.info("获取数据源为:{}", s);
        return s;
    }

    public static void clearDataSource(){
        DATA_SOURCE_HOLDER.remove();
    }


}
